package com.qin.music.mbg;



import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 生成POJO和Mapper
 * @author Leisure
 * create 2022 2022/10/20 19:37
 **/
public class Generator {
    public static void main(String[] args) throws XMLParserException, IOException, InvalidConfigurationException, SQLException, InterruptedException {
        // TODO 警告信息
        ArrayList<String> warnings = new ArrayList<>();
        // TODO 代码重复进行覆盖
        boolean overwrite = true;
        // TODO 反射获取 Class对象
        Class generator = Generator.class;
        // TODO 读取配置文件
        InputStream is = generator.getResourceAsStream("/generatorConfiguartion.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(is);
        is.close();
        // TODO 创建 mbg
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        // TODO 执行生成代码
        myBatisGenerator.generate(null);
        // TODO 输出警告语句
        for (String warning: warnings){
            System.out.println(warning);
        }
    }
}
